home *** CD-ROM | disk | FTP | other *** search
/ World of Video / World of Video.iso / programs / wb / amigaeyes / eyessource.lha / eyesdrawing.c < prev   
C/C++ Source or Header  |  1994-06-11  |  21KB  |  747 lines

  1. /*****************************************************************************/
  2. /*                                 AmigaEyes                                 */
  3. /*                                                                           */
  4. /*       Author: Stéphane Poirier                                            */
  5. /*               Copyright © 1994 Stéphane Poirier. All right reserved       */
  6. /*                                                                           */
  7. /*****************************************************************************/
  8.  
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <graphics/displayinfo.h>
  15. #include <graphics/clip.h>
  16. #include <graphics/view.h>
  17. #include <graphics/layers.h>
  18. #include <graphics/copper.h>
  19. #include <graphics/regions.h>
  20. #include <graphics/rastport.h>
  21. #include <graphics/gfxbase.h>
  22. #include <graphics/gfxmacros.h>
  23. #include <graphics/gels.h>
  24. #include <graphics/gfxbase.h>
  25. #include <clib/graphics_protos.h>
  26. #include <clib/exec_protos.h>
  27. #include <exec/memory.h>
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30. #include <time.h>
  31.  
  32. #include <math.h>
  33. #include <mffp.h>
  34.  
  35. #include "eyes.h"
  36.  
  37. /*
  38. ** Dessin des yeux
  39. */
  40.  
  41. #ifdef ENTRELACE
  42.  int eyeX[37] = {-1,0,1,-2,-1,0,1,2,-3,-2,-1,0,1,2,3,-3,-2,-1,0,1,2,3,-3,-2,-1,0,1,2,3,-2,-1,0,1,2,-1,0,1};
  43.  int eyeY[37] = {-3,-3,-3,-2,-2,-2,-2,-2,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,3,3,3};
  44. #else
  45.  int eyeX[29] = {-1,0,1,-3,-2,-1,0,1,2,3,-4,-3,-2,-1,0,1,2,3,4,-3,-2,-1,0,1,2,3,-1,0,1};
  46.  int eyeY[29] = {-2,-2,-2,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2};
  47. #endif
  48.  
  49. float dcos[]= {  0.999999, 0.998027, 0.992115, 0.982287, 0.968583, 0.951057, 0.929777,
  50.                  0.904827, 0.876307, 0.844328, 0.809017, 0.770513, 0.728969, 0.684547,
  51.                  0.637424, 0.587785, 0.535827, 0.481754, 0.425779, 0.368125, 0.309017,
  52.                  0.248690, 0.187381, 0.125333, 0.062790, 0.000000 };
  53.  
  54. UBYTE *pixel;            /* Pointeur sur le tableau de flags de la fenetre */
  55.  
  56.  
  57. struct Trace
  58. {
  59.   ULONG Adr[WNDY][8];        /* Adresse des lignes d'écran */
  60.   short Depth;            /* Profondeur de l'écran */
  61. } Trace;
  62.  
  63. struct BitMap *SBitmap;        /* La structure SuperBitMap pour la fenetre */
  64.  
  65. void WriteEye(struct Window *, int , int , int , int, int, int, BOOL);
  66. void ClearEye(struct Window *, int , int , int , int, int, int);
  67. BOOL TestWritePixel(int , int , int , int);
  68. BOOL TestClearPixel(int , int , int , int);
  69. BOOL FermePupilleGauche(struct Window *, int, int *);
  70. BOOL OuvrePupilleGauche(struct Window *, int, int *);
  71. BOOL FermePupilleDroite(struct Window *, int, int *);
  72. BOOL OuvrePupilleDroite(struct Window *, int, int *);
  73. void Plot(struct Window *, register SHORT, register SHORT, register int);
  74.  
  75. extern struct parametres Parametres;
  76. extern unsigned int clockInit[];
  77. extern USHORT refresh;
  78.  
  79. /*****************************************************************************/
  80.  
  81. int EyeCloseWindow(BOOL running )
  82. {
  83.     FreeMem(pixel, SIZEWNDX*SIZEWNDY);    /* Libere la memoire allouée */
  84.     return( FALSE);
  85. }
  86.  
  87. /*****************************************************************************/
  88.  
  89. void InitPlot(struct Window *EyeWnd, struct BitMap *SBitmap)
  90. {
  91.   PLANEPTR plan;        /* Pointeur sur un plan de bits */ 
  92.   ULONG addoffset, i;        
  93.   int y;
  94.   UWORD ligne;
  95.  
  96.   Trace.Depth = SBitmap->Depth;    /* Profondeur de l'écran */
  97.   ligne = WNDX >> 4;        /* Calcul de l'adresse du début de chaque ligne */
  98.   if (ligne & 1)
  99.     ligne ++;
  100.   ligne = ligne << 4;
  101.   
  102.   for(y = 0; y < WNDY; y++)
  103.   {
  104.     addoffset = (ligne * y) >> 3;   
  105.     for (i = 0; i < Trace.Depth; i++)
  106.     {
  107.       plan = SBitmap->Planes[i];    /* Adresses des plans ds la SuperBitmap */
  108.       Trace.Adr[y][i] = (ULONG)plan + addoffset;
  109.     }
  110.   }
  111. }
  112.     
  113. /*****************************************************************************/
  114.  
  115. void InitEyes(struct Window *EyeWnd, struct BitMap *SBitmap)
  116. {
  117.   unsigned int clock[2];    /* Horloge */
  118.   int x;
  119.  
  120.   SetRast(EyeWnd->RPort,Parametres.fenetre);        /* Vide la SuperBitMap */
  121.   SetAPen(EyeWnd->RPort,Parametres.bord);        /* Couleur du crayon */
  122.  
  123. #ifdef ENTRELACE
  124.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,15,15);
  125.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,14,14);
  126.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,15,15);
  127.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,14,14);
  128.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,14,15);
  129.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,14,15);
  130.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,15,14);
  131.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,15,14);
  132.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,16,14);
  133.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,16,14);
  134.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,16,15);
  135.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,16,15);
  136.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,13,15);
  137.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,13,15);
  138.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,13,13);
  139.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,13,13);
  140.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,13,14);
  141.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,13,14);
  142. #else
  143.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,17,8);    /* Dessine le contour des yeux */
  144.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,17,8);
  145.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,15,7);
  146.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,15,7);
  147.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,16,7);
  148.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,16,7);
  149.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,14,8);
  150.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,14,8);
  151.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,15,8);
  152.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,15,8);
  153.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,16,8);
  154.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,16,8);
  155.   DrawEllipse(EyeWnd->RPort,lEYE,yEYE,18,8);
  156.   DrawEllipse(EyeWnd->RPort,rEYE,yEYE,18,8);
  157. #endif
  158.  
  159.   x = timer(clock);        /* Prépare la génération de nombres aléatoires */
  160.   srand(clock[1]);
  161.   
  162. /* Allocation d'un tableau de flags représentant l'état de la SuperBitMap */
  163.  
  164.   if((pixel = (UBYTE *)AllocMem(SIZEWNDX*SIZEWNDY,MEMF_PUBLIC|MEMF_CLEAR)) == NULL)
  165.     printf("erreur d'allocation mémoire\n");
  166.  
  167.    LockLayerRom(EyeWnd->WLayer);    /* Recopie les opérations graphiques */
  168.    SyncSBitMap(EyeWnd->WLayer);        /* Dans ma SuperBitMap */
  169.    UnlockLayerRom(EyeWnd->WLayer);
  170.  
  171. }
  172.  
  173. /*****************************************************************************/
  174. /*             Routine de gestion des yeux                 */
  175. /*****************************************************************************/
  176.  
  177. BOOL DrawingEyes(struct Window *EyeWnd, struct BitMap *SBitmap, int offy)
  178. {
  179.   BOOL reveil = FALSE;        /* Valeur de retour: y-a-t-il eu arret de la souris */
  180.                 /* puis mvt ? */
  181.  
  182.   static int xr, yr, xl, yl, mx, my;
  183.   static int compteur_clin_d_oeil_gauche = 0;    /* Compteurs pour clins d'oeil */
  184.   static int compteur_clin_d_oeil_droit = 0;
  185.   static unsigned int wait_cligne_gauche = 02;    /* Delais pour clins d'oeil */
  186.   static unsigned int wait_cligne_droit  = 02;
  187.   float dr, dl, dxl, dxr, dy, x,y;
  188.   int tx, TempsEcoule;
  189.   unsigned int clockVal[2];
  190.   unsigned int xx, yy,i;
  191.   static BOOL debut = TRUE;        /* Premier passage dans la routine */
  192.   static BOOL ferme_pupilles = FALSE;    /* Pupilles fermantes = VRAI sinon FAUX */
  193.   static BOOL ouvre_pupilles = FALSE;    /* Pupilles ouvrante ... */
  194.   static BOOL cligne_gauche = FALSE;    /* Clin d'oeil gauche en cours */
  195.   static BOOL decligne_gauche = FALSE;    /* "Dé"clin d'oeil gauche en cours */
  196.   static BOOL cligne_droit = FALSE;    /* Idem oeil droit */
  197.   static BOOL decligne_droit = FALSE;
  198.   static BOOL pupille_fermee = FALSE;    /* Pupilles fermées */
  199.   static int rRayon = +(REYE-2);      /* Rayon des ellipse pour tracer paupieres */
  200.   static int lRayon = +(REYE-2);
  201.  
  202. /* Est-ce qu'on est pas en train d'ouvrir ou fermer une pupille, ou est-ce
  203. ** les pupilles ne sont pas deja fermees ? 
  204. */
  205.    tx = timer(clockVal);
  206.    TempsEcoule = clockVal[0] - clockInit[0];
  207.  
  208.   if ((!pupille_fermee) && (!ouvre_pupilles) && (!ferme_pupilles))
  209.   {
  210.     if (TempsEcoule > Parametres.timeout) /* Si la souris n'a pas bougé */
  211.       ferme_pupilles = TRUE;  /* durant le temps definit alors on ferme les pupilles */
  212.       
  213.     compteur_clin_d_oeil_gauche++; /* Incrémenter le compteur pour clin d'oeil */
  214.  
  215. /* Est-on prêt à cligner de l'oeil ? et n'est-on pas en train de fermer les
  216. ** pupilles ?
  217. */
  218.     if ((compteur_clin_d_oeil_gauche >= wait_cligne_gauche) && (!ferme_pupilles))
  219.       cligne_gauche = TRUE;
  220.       
  221.     if(decligne_gauche)        /* releve la paupiere */
  222.     {
  223.       for(i = 0; i<REYE*2; i++)
  224.       { 
  225.         decligne_gauche = (!OuvrePupilleGauche(EyeWnd, Parametres.fond, &lRayon));
  226.         WriteEye(EyeWnd, xl, yl, xl, yl, Parametres.pupille, 
  227.                  Parametres.paupiere, decligne_gauche);    /* retrace pupille */
  228.  
  229.         LockLayerRom(EyeWnd->WLayer);    /* Copy le contenue de la SuperBitMap */
  230.         CopySBitMap(EyeWnd->WLayer);    /* Dans la BitMap du Screen */
  231.         UnlockLayerRom(EyeWnd->WLayer);
  232.  
  233.         if (!decligne_gauche) break;
  234.       }
  235.     decligne_gauche = FALSE;
  236.     wait_cligne_gauche = (((unsigned int)rand() >> 23) + (1 << 8)) 
  237.                          / refresh;
  238.     }
  239.  
  240.     if(cligne_gauche)
  241.     {
  242.       for(i = 0; i<2*REYE; i++)
  243.       { 
  244.         cligne_gauche = (!FermePupilleGauche(EyeWnd, Parametres.paupiere, &lRayon));
  245.         LockLayerRom(EyeWnd->WLayer);
  246.         CopySBitMap(EyeWnd->WLayer);
  247.         UnlockLayerRom(EyeWnd->WLayer);
  248.         if (!cligne_gauche) break;
  249.       }
  250.     decligne_gauche = TRUE;
  251.     cligne_gauche = FALSE;
  252.     compteur_clin_d_oeil_gauche = 0;
  253.     }
  254.     
  255.     compteur_clin_d_oeil_droit++;
  256.     if ((compteur_clin_d_oeil_droit >= wait_cligne_droit) && (!ferme_pupilles))
  257.       cligne_droit = TRUE;
  258.       
  259.     if(decligne_droit)
  260.     {
  261.       for(i = 0; i<REYE*2; i++)
  262.       { 
  263.         decligne_droit = (!OuvrePupilleDroite(EyeWnd, Parametres.fond, &rRayon));
  264.         WriteEye(EyeWnd, xr, yr, xr, yr, Parametres.pupille,
  265.                  Parametres.paupiere, decligne_droit);
  266.         LockLayerRom(EyeWnd->WLayer);
  267.         CopySBitMap(EyeWnd->WLayer);
  268.         UnlockLayerRom(EyeWnd->WLayer);
  269.         if (!decligne_droit) break;
  270.       }
  271.     decligne_droit = FALSE;
  272.     wait_cligne_droit = (((unsigned int)rand() >> 23) + (1 << 8))
  273.                         / refresh;
  274.     }
  275.  
  276.     if(cligne_droit)
  277.     {
  278.       for(i = 0; i<2*REYE; i++)
  279.       { 
  280.         cligne_droit = (!FermePupilleDroite(EyeWnd, Parametres.paupiere, &rRayon));
  281.         LockLayerRom(EyeWnd->WLayer);
  282.         CopySBitMap(EyeWnd->WLayer);
  283.         UnlockLayerRom(EyeWnd->WLayer);
  284.         if (!cligne_droit) break;
  285.       }
  286.     decligne_droit = TRUE;
  287.     cligne_droit = FALSE;
  288.     compteur_clin_d_oeil_droit = 0;
  289.     }
  290.   }
  291.   
  292.   if (ferme_pupilles)
  293.   {
  294.     ferme_pupilles = (!FermePupilleGauche(EyeWnd, Parametres.paupiere, &lRayon));
  295.     ferme_pupilles = (!FermePupilleDroite(EyeWnd, Parametres.paupiere, &rRayon));
  296.     LockLayerRom(EyeWnd->WLayer);
  297.     CopySBitMap(EyeWnd->WLayer);
  298.     UnlockLayerRom(EyeWnd->WLayer);
  299.     pupille_fermee = !ferme_pupilles;
  300.   }
  301.  
  302.   if (ouvre_pupilles)
  303.   {
  304.     ouvre_pupilles = (!OuvrePupilleGauche(EyeWnd, Parametres.fond, &lRayon));
  305.     ouvre_pupilles = (!OuvrePupilleDroite(EyeWnd, Parametres.fond, &rRayon));
  306.     LockLayerRom(EyeWnd->WLayer);
  307.     CopySBitMap(EyeWnd->WLayer);
  308.     UnlockLayerRom(EyeWnd->WLayer);
  309.     WriteEye(EyeWnd, xl, yl, xl, yl, Parametres.pupille,
  310.              Parametres.paupiere, ouvre_pupilles);
  311.     WriteEye(EyeWnd, xr, yr, xr, yr, Parametres.pupille,
  312.              Parametres.paupiere, ouvre_pupilles);
  313.   }
  314.     
  315.   if  ((EyeWnd->MouseX != mx + OFFX) || (EyeWnd->MouseY != my + offy))
  316.   {
  317.     if (TempsEcoule > 1)    /* On renvoie "reveil" si 1 sec au moins */
  318.       reveil = TRUE;            /* s'est ecoulée depuis le dernier mvt. */
  319.  
  320.     clockInit[1] = clockVal[1];
  321.     clockInit[0] = clockVal[0];
  322.     
  323.     refresh = Parametres.refresh;
  324.     
  325.     if((ferme_pupilles) || (pupille_fermee))
  326.     {
  327.       ouvre_pupilles = TRUE;
  328.       ferme_pupilles = FALSE;
  329.       pupille_fermee = FALSE;
  330.     }
  331.     
  332.     mx = EyeWnd->MouseX - OFFX;
  333.     my = EyeWnd->MouseY - offy;
  334.     
  335.     dxl = (float)mx - (float)lEYE;    /* Distance de la pupille au pointeur */
  336.     dxr = (float)mx - (float)rEYE;
  337.     dy  = (float)my - (float)yEYE;
  338.     dl = sqrt(SQR(dxl) + SQR(dy));
  339.     dr = sqrt(SQR(dxr) + SQR(dy));
  340.  
  341.     if (dl > RLIM)            /* Si distance > rayon de l'oeil */
  342.     {
  343.       x = (float)RLIM/dl * dxl + (float)lEYE;
  344. #ifdef ENTRELACE
  345.       y = (float)RLIM/dl * dy  + (float)yEYE;
  346. #else
  347.       y = ((float)REYE/dl * dy)/2 + (float)yEYE;
  348. #endif
  349.       xx = (int)(x+0.5);
  350.       yy = (int)(y+0.5);
  351.     }
  352.     else                /* Sinon Pupille sous le pointeur */
  353.     {
  354.       xx = mx;
  355.       yy = my;
  356.     }  
  357.     if ((xl != xx) || (yl != yy))    /* Si la pupille est déplacée */
  358.     {                    /* Alors on la redessine */
  359.       WriteEye(EyeWnd, xx, yy, xl, yl, Parametres.pupille,
  360.                Parametres.paupiere, ouvre_pupilles);
  361.      if (debut == FALSE)
  362.         ClearEye(EyeWnd, xx, yy, xl, yl, Parametres.fond, Parametres.paupiere);
  363.       xl = xx; yl = yy;
  364.     }
  365.  
  366.     if (dr > RLIM)            /* Idem pupille droite */
  367.     {
  368.       x = (float)RLIM/dr * dxr + (float)rEYE;
  369. #ifdef ENTRELACE
  370.       y = (float)RLIM/dr * dy  + (float)yEYE;
  371. #else
  372.       y = ((float)REYE/dr * dy)/2 + (float)yEYE;
  373. #endif
  374.       xx = (int)(x+0.5);
  375.       yy = (int)(y+0.5);
  376.     }
  377.     else
  378.     {
  379.       xx = mx;
  380.       yy = my;
  381.     }
  382.     if ((xr != xx) || (yr != yy))
  383.     {
  384.       WriteEye(EyeWnd, xx, yy, xr, yr, Parametres.pupille,
  385.                Parametres.paupiere, ouvre_pupilles);
  386.       if (debut == FALSE)
  387.         ClearEye(EyeWnd, xx, yy, xr, yr, Parametres.fond, Parametres.paupiere);
  388.       xr = xx; yr = yy;
  389.     }
  390.    LockLayerRom(EyeWnd->WLayer);
  391.    CopySBitMap(EyeWnd->WLayer);
  392.    UnlockLayerRom(EyeWnd->WLayer);
  393.   }
  394.   else
  395.   {
  396.     if (TempsEcoule >= 1)               /* Si la souris n'a pas bougé */
  397.     {
  398.       refresh = SLEEP;            /* pendant au moins 1 sec. */
  399.     }
  400.     
  401.   }
  402.   debut = FALSE;
  403.   return (reveil);
  404. }
  405.  
  406. /*****************************************************************************/
  407. /*               Dessine une pupille                     */
  408. /*****************************************************************************/
  409.  
  410. void WriteEye(struct Window *EyeWnd, int x, int y, 
  411.               int xold, int yold, int c1, int c2, BOOL ouvre_pupille)
  412. {
  413.   register int i, x1, y1;
  414.   UBYTE *c;
  415.   
  416.   SetAPen(EyeWnd->RPort,c1);
  417.   
  418. #ifdef ENTRELACE
  419.   for (i=0; i < 37; i++)    /* Chaque pupille comporte 37 pixels en version LACE */
  420. #else
  421.   for (i=0; i < 29; i++)        /* Chaque pupille comporte 29 pixels */
  422. #endif
  423.   {
  424.     x1 = x+eyeX[i];
  425.     y1 = y+eyeY[i];
  426.     c = pixel+SIZEWNDX*x1+y1;
  427.     
  428.       if ((*c != c2) && (*c != c1))    /* Si le point n'est pas deja affiché */
  429.       {
  430.         Plot(EyeWnd, x1, y1, c1);
  431.         *c = c1;
  432.       }
  433.  
  434.   }
  435. }
  436.  
  437. /*****************************************************************************/
  438. /*                Efface une pupille                     */
  439. /*****************************************************************************/
  440.  
  441. void ClearEye(struct Window *EyeWnd, int x, int y, int xold, int yold, int c1, int c2)
  442. {
  443.   register int i, x1, y1;
  444.   UBYTE *c;
  445.   
  446.   SetAPen(EyeWnd->RPort,c1);
  447.   
  448. #ifdef ENTRELACE
  449.   for (i = 0; i < 37; i++)    /* Chaque pupille comporte 37 pixels en version LACE */
  450. #else
  451.   for (i = 0; i < 29; i++)        /* Chaque pupille comporte 29 pixels */
  452. #endif
  453.   {
  454.     x1 = xold+eyeX[i];
  455.     y1 = yold+eyeY[i];
  456.     c = pixel+SIZEWNDX*x1+y1;
  457.  
  458.     if (!TestClearPixel(x1, y1, x, y))
  459.       if (*c != c2)
  460.       {
  461.         Plot(EyeWnd, x1, y1, c1);
  462.         *c = c1;
  463.       }
  464.  
  465.   }
  466. }
  467.  
  468. /*****************************************************************************/
  469. /*        Test pour déterminer si on peut effacer un pixel         */
  470. /*****************************************************************************/
  471.  
  472. BOOL TestClearPixel(int x, int y, int xnew, int ynew)
  473. {
  474.   register int i;
  475.   BOOL ret = FALSE;
  476.   
  477. #ifdef ENTRELACE
  478.   for (i = 0; i < 37; i++)    /* Chaque pupille comporte 37 pixels en version LACE */
  479. #else
  480.   for (i = 0; i < 29; i++)        /* Chaque pupille comporte 29 pixels */
  481. #endif
  482.   {
  483.     if ((x == xnew + eyeX[i]) && (y == ynew + eyeY[i]))
  484.     {
  485.       ret = TRUE;
  486.       break;
  487.     }
  488.   }
  489.   return(ret);
  490. }
  491.  
  492. /*****************************************************************************/
  493.  
  494. BOOL FermePupilleGauche(struct Window *EyeWnd, int c, int * PRayon)
  495. {
  496.   SHORT i, xp, yp;
  497. #ifdef ENTRELACE
  498.   static float rx = REYE-0.5;
  499. #else
  500.   static float rx = 2*REYE+0.5;
  501. #endif
  502.   float ry, x, y;
  503.   
  504.   float sgn = 1;
  505.   
  506.   if (*PRayon < 0)
  507.   {
  508.     sgn = -1;
  509.     ry = -(*PRayon);
  510.   }
  511.   else
  512.   {
  513.     ry = *PRayon;
  514.   }
  515.  
  516.   SetAPen(EyeWnd->RPort, c);
  517.   
  518.   for (i = 0; i <= RESOL; i++)
  519.   {
  520.     x = (float)rx * sgn*dcos[i];
  521.     y = -(float)ry * sgn*dcos[RESOL-i];
  522.     
  523.     xp = (int)(x+0.5+lEYE);
  524.     yp = (int)(y+0.5+yEYE);    
  525.     Plot(EyeWnd, xp, yp, c);
  526.     *(pixel+SIZEWNDX*xp+yp) = c;
  527.     
  528.     xp = (int)(-x+0.5+lEYE);
  529.     Plot(EyeWnd, xp, yp, c);
  530.     *(pixel+SIZEWNDX*xp+yp) = c;
  531.   }
  532.  
  533.   (*PRayon)--;
  534. #ifdef ENTRELACE
  535.   if (*PRayon < -(REYE-2))
  536. #else
  537.   if (*PRayon < -(REYE-1))
  538. #endif
  539.   {
  540.     (*PRayon)++;
  541.     return(TRUE);
  542.   }
  543.   else
  544.     return(FALSE);
  545. }
  546.  
  547. /*****************************************************************************/
  548.  
  549. BOOL OuvrePupilleGauche(struct Window *EyeWnd, int c, int *PRayon)
  550. {
  551.   SHORT i, xp, yp;
  552. #ifdef ENTRELACE
  553.   static float rx = REYE-0.5;
  554. #else
  555.   static float rx = REYE*2+0.5;
  556. #endif
  557.   float ry, x, y;
  558.   
  559.   float sgn = 1;
  560.   
  561.   if (*PRayon < 0)
  562.   {
  563.     sgn = -1;
  564.     ry = -*PRayon;
  565.   }
  566.   else
  567.   {
  568.     ry = *PRayon;
  569.   }
  570.  
  571.   SetAPen(EyeWnd->RPort, c);
  572.   
  573.   for (i = 0; i <= RESOL; i++)
  574.   {
  575.     x = (float)rx * sgn*dcos[i];
  576.     y = -(float)ry * sgn*dcos[RESOL-i];
  577.     
  578.     xp = (int)(x+lEYE+0.5);
  579.     yp = (int)(y+yEYE+0.5);    
  580.     Plot(EyeWnd, xp, yp, c);
  581.     *(pixel+SIZEWNDX*xp+yp) = c;
  582.     
  583.     xp = (int)(-x+lEYE+0.5);
  584.     Plot(EyeWnd, xp, yp, c);
  585.     *(pixel+SIZEWNDX*xp+yp) = c;
  586.   }
  587.  
  588.   (*PRayon)++;
  589. #ifdef ENTRELACE
  590.   if (*PRayon > (REYE-2))
  591. #else
  592.   if (*PRayon > (REYE-1))
  593. #endif
  594.   {
  595.     (*PRayon)--;
  596.     return(TRUE);
  597.   }
  598.   else
  599.    return(FALSE);
  600. }
  601.  
  602. /*****************************************************************************/
  603.  
  604. BOOL FermePupilleDroite(struct Window *EyeWnd, int c, int * PRayon)
  605. {
  606.   SHORT i, xp, yp;
  607. #ifdef ENTRELACE
  608.   static float rx = REYE-0.5;
  609. #else
  610.   static float rx = REYE*2+0.5;
  611. #endif
  612.   float ry, x, y;
  613.   
  614.   float offsetangle = 0;
  615.   float sgn = 1;
  616.   
  617.   if (*PRayon < 0)
  618.   {
  619.     offsetangle = PI;
  620.     sgn = -1;
  621.     ry = -(*PRayon);
  622.   }
  623.   else
  624.   {
  625.     ry = *PRayon;
  626.   }
  627.  
  628.   SetAPen(EyeWnd->RPort, c);
  629.   
  630.   for (i = 0; i <= RESOL; i++)
  631.   {
  632.     x = (float)rx * sgn*dcos[i];
  633.     y = -(float)ry * sgn*dcos[RESOL-i];
  634.     
  635.     xp = (int)(x+rEYE+0.5);
  636.     yp = (int)(y+yEYE+0.5);    
  637.     Plot(EyeWnd, xp, yp, c);
  638.     *(pixel+SIZEWNDX*xp+yp) = c;
  639.     
  640.     xp = (int)(-x+rEYE+0.5);
  641.     Plot(EyeWnd, xp, yp, c);
  642.     *(pixel+SIZEWNDX*xp+yp) = c;
  643.   }
  644.  
  645.   (*PRayon)--;
  646.  
  647. #ifdef ENTRELACE
  648.   if (*PRayon < -(REYE-2))
  649. #else
  650.   if (*PRayon < -(REYE-1))
  651. #endif
  652.   {
  653.     (*PRayon)++;
  654.     return(TRUE);
  655.   }
  656.   else
  657.     return(FALSE);
  658. }
  659.  
  660. /*****************************************************************************/
  661.  
  662. BOOL OuvrePupilleDroite(struct Window *EyeWnd, int c, int *PRayon)
  663. {
  664.   SHORT i, xp, yp;
  665. #ifdef ENTRELACE
  666.   static float rx = REYE-0.5;
  667. #else
  668.   static float rx = REYE*2+0.5;
  669. #endif
  670.   float ry, x, y;
  671.   
  672.   float offsetangle = 0;
  673.   float sgn = 1;
  674.   
  675.   if (*PRayon < 0)
  676.   {
  677.     offsetangle = PI;
  678.     sgn = -1;
  679.     ry = -*PRayon;
  680.   }
  681.   else
  682.   {
  683.     ry = *PRayon;
  684.   }
  685.  
  686.   SetAPen(EyeWnd->RPort, c);
  687.   
  688.   for (i = 0; i <= RESOL; i++)
  689.   {
  690.     x = (float)rx * sgn*dcos[i];
  691.     y = -(float)ry * sgn*dcos[RESOL-i];
  692.     
  693.     xp = (int)(x+rEYE+0.5);
  694.     yp = (int)(y+yEYE+0.5);    
  695.     Plot(EyeWnd, xp, yp, c);
  696.     *(pixel+SIZEWNDX*xp+yp) = c;
  697.     
  698.     xp = (int)(-x+rEYE+0.5);
  699.     Plot(EyeWnd, xp, yp, c);
  700.     *(pixel+SIZEWNDX*xp+yp) = c;
  701.   }
  702.  
  703.   (*PRayon)++;
  704.  
  705. #ifdef ENTRELACE
  706.   if (*PRayon > (REYE-2))
  707. #else
  708.   if (*PRayon > (REYE-1))
  709. #endif
  710.   {
  711.     (*PRayon)--;
  712.     return(TRUE);
  713.   }
  714.   else
  715.    return(FALSE);
  716. }
  717.  
  718. /*****************************************************************************/
  719. /*            Routine d'affichage d'un point                 */
  720. /*****************************************************************************/
  721.  
  722. void Plot(struct Window *EyeWnd, register SHORT x, register SHORT y, register int c)
  723. {
  724.   register UBYTE *adresse;
  725.   UBYTE bit;
  726.   register etbit, oubit;
  727.   register ULONG addoffset, i;
  728.       
  729.   if ((x <= EyeWnd->Width) && (y <= EyeWnd->Height))
  730.   {
  731.     addoffset = x >> 3;
  732.  
  733.     bit = 7 - (x & 7);
  734.     oubit = 1 << bit;
  735.     etbit = 255 - oubit;
  736.     
  737.     for (i = 0; i < Trace.Depth; i++, c = c >> 1)
  738.     {
  739.       adresse = (UBYTE *)(Trace.Adr[y][i] + addoffset);
  740.       if (c & 1)
  741.         *(adresse) |= oubit;
  742.       else
  743.         *(adresse) &= etbit;
  744.     }
  745.   }
  746. }
  747.